<template>
  <section class="container">
    <div class="video-player-box vjs-custom-skin"
         :playsinline="playsinline"
         @play="onPlayerPlay($event)"
         @pause="onPlayerPause($event)"
         @ended="onPlayerEnded($event)"
         @loadeddata="onPlayerLoadeddata($event)"
         @waiting="onPlayerWaiting($event)"
         @playing="onPlayerPlaying($event)"
         @timeupdate="onPlayerTimeupdate($event)"
         @canplay="onPlayerCanplay($event)"
         @canplaythrough="onPlayerCanplaythrough($event)"
         @ready="playerReadied"
         @statechanged="playerStateChanged($event)"
         v-video-player:myVideoPlayer="playerOptions">
    </div>
  </section>
</template>

<script>
  export default {
    data() {
      return {
        // component options
        playsinline: true,

        // videojs options
        playerOptions: {
          controls: true,
          autoplay: true,//如果true,浏览器准备好时开始回放。
          muted: true,  // 默认情况下将会消除任何音频。
          loop: false, // 导致视频一结束就重新开始。
          preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
          // aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
          fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
          language: 'en',
          playbackRates: [0.7, 1.0, 1.5, 2.0],
          sources: [{
            type: 'video/mp4',
            src: this.videoUrl
          }],
          notSupportedMessage: '此视频暂无法播放，请稍后再试',//允许覆盖Video.js无法播放媒体源时显示的默认信息。
          // poster: "/static/images/author.jpg", //封面图

          controlBar: {
            timeDivider: false,
            durationDisplay: false,
            remainingTimeDisplay: false,
            fullscreenToggle: true  //全屏按钮
          }

        }
      }
    },
    props: {
      videoUrl: {
        type: String,
        default: ''
      }
    },
    mounted() {
      // console.log('this is current player instance object', this.myVideoPlayer)
    },
    methods: {
      // listen event
      onPlayerPlay(player) {
        // console.log('player play!', player)
      },
      onPlayerPause(player) {
        // console.log('player pause!', player)
      },
      onPlayerEnded(player) {
        // console.log('player ended!', player)
      },
      onPlayerLoadeddata(player) {
        // console.log('player Loadeddata!', player)
      },
      onPlayerWaiting(player) {
        // console.log('player Waiting!', player)
      },
      onPlayerPlaying(player) {
        // console.log('player Playing!', player)
      },
      onPlayerTimeupdate(player) {
        // console.log('player Timeupdate!', player.currentTime())
      },
      onPlayerCanplay(player) {
        // console.log('player Canplay!', player)
      },
      onPlayerCanplaythrough(player) {
        // console.log('player Canplaythrough!', player)
      },
      // or listen state event
      playerStateChanged(playerCurrentState) {
        // console.log('player current update state', playerCurrentState)
      },
      // player is ready
      playerReadied(player) {
        // console.log('example 01: the player is readied', player)
      }
    }
  }
</script>

<style lang="scss">
  .container {
    width: 100%;
    height: 84.3%;
    margin: 0 auto;

    .video-player-box {
      width: 100%;
      height: 100%;

      .video-js.vjs-fluid, #vjs_video_3, .vjs_video_3-dimensions {
        width: 100% !important;
        height: 100% !important;
      }

      .vjs-has-started .vjs-control-bar {
        opacity: 0;
      }

      .vjs-big-play-button {
        width: 80px;
        height: 80px;
        left: 50%;
        top: 50%;
        transform: translate(-40px, -40px);
        border-radius: 50%;

        .vjs-icon-placeholder:before, .vjs-icon-play:before {
          top: 16px !important;
        }
      }

      .video-js .vjs-tech {
        height: 100%;
        width: auto;
      }


    }
  }
</style>
